import { globalVariable } from "../globalVariable/globalVariable";
import { networkInterface } from "../globalVariable/networkInterface";

export class request {
	getHospitalInfo() {
		return new Promise((resolve, reject) => {
			uni.request({
				url: networkInterface.getHosBaseInfo,
				method: "GET",
				success: (res) => {
					console.log(res.data);
					if (res['code'] == 200) {
						resolve(res['data']);
					}
				}
			});
		})

	}

	getHealthCard(carId : string) {
		return new Promise((resolve, reject) => {
			uni.request({
				url: networkInterface.getHealthCard + '/' + carId,
				method: "GET",
				success: (res) => {
					if (res['data']['code'] == 200) {
						resolve(res['data']['data']);
					} else {
						// reject("未查询到该身份证的健康卡信息，请前往创建健康卡");
						reject("未查询到该身份证的健康卡信息，请前往创建健康卡");
					}
				}
			});
		})
	}

	getDepartmentQuery() {
		return new Promise((resolve, reject) => {
			uni.request({
				url: networkInterface.getDepartmentQuery,
				method: "GET",
				success: (res) => {
					if (res['data']['code'] == 200) {
						resolve(res['data']['data'])
					} else {
						reject(res['data']['msg'])
					}
				}
			})

		})
	}

	postNumberSourceQuery(time : string, depId : string) {
		return new Promise((reseolve, reject) => {
			uni.request({
				url: networkInterface.postNumberSourceQuery,
				data: {
					time: time,
					depId: depId
				},
				method: "POST",
				success: (res) => {
					if (res['data']['code'] == 200) {
						if (Array.isArray(res['data']['data']['GROUP']['HBLIST']['HB'])) {
							reseolve({ type: 'Array', data: res['data']['data'] })
						} else {
							reseolve({ type: 'object', data: res['data']['data'] })
						}
					} else {
						reject(res['data']['msg'])
					}
				}
			})
		})
	}



	postAddHealthyCard(data : AddHealthyCard) {
		return new Promise((resolve, reject) => {
			uni.request({
				url: networkInterface.postAddHealthyCard,
				method: "POST",
				data: data,
				success: (res) => {
					if (res['data']['code'] == 200) {
						resolve(true)
					} else {
						reject(res['data']['msg'])
					}
				}
			})
		})
	}

	postApprequestLockSource(data : object) {
		return new Promise((resolve, reject) => {
			uni.request({
				url: networkInterface.postApprequestLockSource,
				method: "POST",
				data: data,
				success: (res) => {
					if (res['data']['code'] == 200) {
						resolve(res['data']['data'])
					} else {
						reject(res['data']['msg'])
					}
				}
			})
		})
	}

	postRegisteredOrder(data : object) {
		return new Promise((resolve, reject) => {
			uni.request({
				url: networkInterface.postRegisteredOrder,
				method: "POST",
				data: data,
				success: (res) => {
					if (res['data']['code'] == 200) {
						resolve(res['data']['data'])
					} else {
						reject(res['data']['msg'])
					}
				}
			})
		})
	}

	getRegister(id : string) {
		return new Promise((resolve, reject) => {
			uni.request({
				url: networkInterface.getRegister + '/' + id,
				method: "GET",
				success: (res) => {
					if (res['data']['code'] == 200) {
						resolve(res['data']['data']);
					} else {
						// reject("未查询到该身份证的健康卡信息，请前往创建健康卡");
						reject(res['data']['msg']);
					}
				}
			});
		})
	}

	postPaymentNote() {
		return new Promise((resolve, reject) => {
			uni.request({
				url: networkInterface.postPaymentNote,
				method: "POST",
				data: {
					cardId: globalVariable.cardId,
					"days": 1
				},
				success: (res) => {
					if (res['data']['code'] == 200) {
						resolve(res['data']['data']);
					} else {
						reject(res['data']['msg']);
					}
				}
			});
		})
	}
	
	postBatchPayDev(data:object){
		return new Promise((resolve, reject) => {
			uni.request({
				url: networkInterface.postBatchPayDev,
				method: "POST",
				data:data,
				success: (res) => {
					if (res['data']['code'] == 200) {
						resolve(res['data']['data']);
					} else {
						reject(res['data']['msg']);
					}
				}
			});
		})
	}
	
	getRecordXmlDetailJYQuery(id:string){
		return new Promise((resolve, reject) => {
			uni.request({
				url: networkInterface.getRecordXmlDetailJYQuery+"/"+id,
				method: "GET",
				success: (res) => {
					if (res['data']['code'] == 200) {
						resolve(res['data']['data']);
					} else {
						reject(res['data']['msg']);
					}
				}
			});
		})
	}
	
	getRecordXmlDetail(id:string){
		return new Promise((resolve, reject) => {
			uni.request({
				url: networkInterface.getRecordXmlDetail+"/"+id,
				method: "GET",
				success: (res) => {
					if (res['data']['code'] == 200) {
						resolve(res['data']['data']);
					} else {
						reject(res['data']['msg']);
					}
				}
			});
		})
	}
	
	getArticleList(){
		return new Promise((resolve,reject)=>{
			uni.request({
				url:networkInterface.getArticleList+"?cid="+globalVariable.articleListId,
				method: "GET",
				success: (res) => {
					if (res['data']['code'] == 200) {
						resolve(res['data']['data']);
					} else {
						reject(res['data']['msg']);
					}
				}
			})
		})
	}
	
	getArticleDetail(){
		return new Promise((resolve,reject)=>{
			uni.request({
				url:networkInterface.getArticleDetail+"?id="+globalVariable.articleDetailId,
				method: "GET",
				success: (res) => {
					if (res['data']['code'] == 200) {
						resolve(res['data']['data']);
					} else {
						reject(res['data']['msg']);
					}
				}
			})
		})
	}
	
	
	recordJCQuery(data:object){
		return new Promise((resolve,reject)=>{
			uni.request({
				url:networkInterface.recordJCQuery,
				method: "POST",
				data:data,
				success: (res) => {
					if (res['data']['code'] == 200) {
						resolve(res['data']['data']);
					} else {
						reject(res['data']['msg']);
					}
				}
			})
		})
	}
	
	recordJYQuery(data:object){
		return new Promise((resolve,reject)=>{
			uni.request({
				url:networkInterface.recordJYQuery,
				method: "POST",
				data:data,
				success: (res) => {
					if (res['data']['code'] == 200) {
						resolve(res['data']['data']);
					} else {
						reject(res['data']['msg']);
					}
				}
			})
		})
	}
	
	
}

export class AddHealthyCard {
	idNumber : string;
	birthday : string;
	realName : string;
	mobile : string;
	sex : number;
	nation : string;
	province : string;
	city : string;
	area : string;
	address : string
}